package com.cloneoner.test
{
	import flash.geom.Rectangle;
	import flash.geom.Point;
	import flash.filters.BlurFilter;
	import com.cloneoner.test.BmpMediaViewer;


	/**
	 * @author Thibault Loup
	 */
	public class BlurBmpd extends BmpMediaViewer
	{
		
		public function BlurBmpd(pWidth : int, pHeight : int)
		{
			super(pWidth, pHeight);
			
			_init();
			_bmpd.applyFilter(_bmpd, _rect, _point, _blur);
		}
		
		
		override protected function _render() : void
		{
			super._render();
			
			var r:Number;
			var b:Number;
			var currenBlur:Number;
			
			if( _ratio <= _coeff)
			{
				r = _ratio / _coeff;
				b = r*_maxBlur;
				currenBlur = _blur.blurX >  b ? _blur.blurX : b;
			}
			else 
			{
				r = (1-_ratio )/ (1-_coeff);
				b = r*_maxBlur;
				currenBlur = b;
			}
			
			trace("_ratio : " + _ratio);
//			trace("current : " + currenBlur);
			
			_blur.blurX = _blur.blurY = currenBlur;
			
			_bmpd.applyFilter(_bmpd, _rect, _point, _blur);
		}
		
		private function _init() : void
		{
			_rect = new Rectangle(0, 0, _width, _height);
			_point = new Point();
			_blur = new BlurFilter();
		}
		
		
		private var _blur:BlurFilter;
		private var _point:Point;
		
		private var _maxBlur:int = 10;
		private var _coeff:Number = .6;
		private var _rect:Rectangle;
	}
}
